<style lang="less">
	/*@import './international.less';*/
</style>

<template>
	<div>
		<Row type="flex" justify="center">
			<Col span="20">
			<Form :model="form" :label-width="80" inline>
				<FormItem label="package">
					<Input v-model="form.packageName" placeholder="com.labofjet.system" :style="{width:'300px'}"></Input>
				</FormItem>
				<FormItem label="table">
					<Input v-model="form.table" placeholder="sys_user" :style="{width:'200px'}"></Input>
				</FormItem>
				<Button type="primary" @click="generate">生成</Button>
			</Form>
			</Col>
		</Row>

		<Row type="flex" justify="center">
			<Col span="20">
			<Tabs value="name1">
				<TabPane label="Controller" name="Controller">
					<Form :label-width="80">
						<FormItem label="文件名:">
							<Input :value="generateFileName('controller')"></Input>
						</FormItem>
					</Form>
					<Form :label-width="80">
						<FormItem label="code:">
							<Input :value="sysCodeDto.controllerCode" type="textarea" :rows="30"></Input>
						</FormItem>
					</Form>
				</TabPane>
				<TabPane label="ServiceImpl" name="ServiceImpl">
					<Form :label-width="80">
						<FormItem label="文件名:">
							<Input :value="generateFileName('serviceImpl')"></Input>
						</FormItem>
					</Form>
					<Form :label-width="80">
						<FormItem label="code:">
							<Input :value="sysCodeDto.serviceImplCode" type="textarea" :rows="30"></Input>
						</FormItem>
					</Form>
				</TabPane>
				<TabPane label="Mapper" name="Mapper">
					<Form :label-width="80">
						<FormItem label="文件名:">
							<Input :value="generateFileName('mapper')"></Input>
						</FormItem>
					</Form>
					<Form :label-width="80">
						<FormItem label="code:">
							<Input :value="sysCodeDto.mapperCode" type="textarea" :rows="30"></Input>
						</FormItem>
					</Form>
				</TabPane>
				<TabPane label="MapperXML" name="MapperXML">
					<Form :label-width="80">
						<FormItem label="文件名:">
							<Input :value="generateFileName('mapperXML')"></Input>
						</FormItem>
					</Form>
					<Form :label-width="80">
						<FormItem label="code:">
							<Input :value="sysCodeDto.mapperXMLCode" type="textarea" :rows="30"></Input>
						</FormItem>
					</Form>
				</TabPane>
				<TabPane label="VuePage" name="VuePage">
					<Form :label-width="80">
						<FormItem label="文件名:">
							<Input :value="generateFileName('vuePage')"></Input>
						</FormItem>
					</Form>
					<Form :label-width="80">
						<FormItem label="code:">
							<Input :value="sysCodeDto.vuePageCode" type="textarea" :rows="30"></Input>
						</FormItem>
					</Form>
				</TabPane>
			</Tabs>
			</Col>
		</Row>
	</div>
</template>

<script>

    import util from '@/libs/util';

    export default {
        name: 'code-page',
        components: {},
        props: {},
        data () {
            return {
                form: {
                    packageName: 'com.labofjet.system',
                    table: 'sys_test'
                },
                sysCodeDto: {}
            };
        },
        methods: {
            generate(){
                let me = this;
                util.post({
                    url: "code/generate",
                    data: me.form,
                    ajaxSuccess: (res) => {
                        util.commonAjaxSuccess(res);
                        let context = res.data;
                        me.sysCodeDto = context.data;
                    }
                });
            },
            generateFileName(s){
                let me = this;
                let sysCodeDto = me.sysCodeDto;
                if (!sysCodeDto.className) {
                    return "";
                }
                if (s === "controller") {
                    return sysCodeDto.className + "Controller.java";
                }
                if (s === "serviceImpl") {
                    return sysCodeDto.className + "ServiceImpl.java";
                }
                if (s === "mapper") {
                    return sysCodeDto.className + "Mapper.java";
                }
                if (s === "mapperXML") {
                    return sysCodeDto.className + "Mapper2.xml";
                }
                if (s === "vuePage") {
                    return sysCodeDto.url + "-page.vue";
                }
                return "none";
            }
        },
        created () {
        },
        mounted() {

        }
    };
</script>
